Week 1 Answers (0902)

Author

Danny Po-Hsien Kang

Published

September 2, 2025

1 Assign Values

Create two variables called x and y, and assign values 20250902 and 1031. Compute x / y.

x <- 20250902
y <- 1031
print(x / y)

2 Help

Use the help() function to check docs, e.g. data.frame() or mean().

help(data.frame)
help(mean)

3 Matrix

Create the following vectors:

name_vec <- c("James", "Noc", "Monica")

age_vec <- c(25, 30, 28)

and create a 3 × 2 matrix with these two vectors.

Do you encounter errors? Can you print the matrix out? What’s the data type of the matrix?

name_vec <- c("James", "Noc", "Monica")
age_vec <- c(25, 30, 28)
mat <- matrix(c(name_vec, age_vec), nrow = 3)
print(mat)
class(mat)

# `mat[,2]` only select the second column
# note that the `age_vec` become character type after merging into matrix
print(mat[,2])
class(mat[,2])